<?php
/**
 * 描述
 * Created by Paco
 * Date: 2018/10/5 Time: 10:29
 */

namespace App\Http\Controllers\Api;


use App\Http\Controllers\Controller;
use App\Traits\ApiRespond;
use Illuminate\Http\Request;

class UploadController extends Controller
{
    use ApiRespond;

    function upload(Request $request)
    {

        $file = $request->file('img_file');
        if ($file) {
            $path = storage_path('uploads');
            $path = $path . '/' . date('Ym');
            if (!file_exists($path)) {
                mkdir($path);
            }
            $extension = $file->guessExtension();
            $newName = uniqid() . "." . $extension;
            $file->move($path, $newName);
            $receipt_img =  date('Ym') . '/' . $newName;
            return $this->respondWith(['img_url' => $receipt_img]);
        } else {
            return $this->respondError(10111);
        }

    }
}